///<reference path='../typings/tsd.d.ts'/>
import hprose = require("hprose");

import Config from "./config/Config";
import DataController from "./controller/DataController";
let CaptureFilter = require("./filter/CaptureFilter");

const uri: string = Config.NET_PROTOCOL + "://" + Config.HOST_IP + ":" + Config.HOST_PORT;
function SpreadModuleServer(): void {
    const server = new hprose.Server(uri);
    const asyncOptions = {async: true};
    server.addFilter(CaptureFilter);

    server.addFunction(function(keystore,pwDerivedKey: Uint8Array,data: string,callback: Function){
        let myData = new DataController(keystore,pwDerivedKey);
        myData.storeData(data,callback);
    },"storeData",asyncOptions);

    
    server.addFunction(function(keystore,pwDerivedKey: Uint8Array,data: string,callback: Function){
        let myData = new DataController(keystore,pwDerivedKey);
        myData.storeCiphereData(data,callback);
    },"storeCiphereData",asyncOptions);

    server.addFunction(function(keystore,pwDerivedKey: Uint8Array,hash: string,callback: Function){
        let myData = new DataController(keystore,pwDerivedKey);
        myData.getDecipcherData(hash,callback);
    },"getDecipcherData",asyncOptions);

    server.start();
}

SpreadModuleServer();
console.log("[SpreadModuleServer] rpc server started");
console.log("[SpreadModuleServer] server at :" + uri);